<template>
    <el-tree :props="props" :load="loadNode" lazy @node-click="clickHandle" hightlight-current accordion>
    </el-tree>

</template>

<script>
export default {
    data() {
        return {
            props: {
                label: 'name',
                children: 'zones',
                isLeaf: 'leaf'
            },
    };
},
methods: {
    loadNode(node, resolve) {
        if (node.level === 0) {
            this.$api.selectItemCategoryByParentId({ type: 1 }).then(res => {
                console.log("树状图---treeNode：", res)
                if (res.data.code == 200) {
                    return resolve(res.data.resultValue);
                } else {
                    return resolve([])
                }
            })
        }
        if (node.level >= 1) {
            //请求---
            this.$api.selectItemCategoryByParentId({ type: node.data.cid }).then(res => {
                console.log("树状图---treeNode：", res)
                if (res.data.code == 200) {
                    return resolve(res.data.resultValue);
                } else {
                    return resolve([])
                }
            })
        }
        if (node.level >= 1) return resolve([]);
    },
    //点击树状图，出现以下事件
    clickHandle(data, node) {
        console.log(data)
        console.log(node)
        this.$emit('sendTreeData', data)

    }

},
};
</script>

<style lang="less" scoped>
//选中高亮
    /deep/ .el-tree-node:focus > .el-tree-node__content {
      background-color: rgb(147, 184, 211) !important;
    }


</style>